﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Frogism.Core;
using Frogism.Domain;
using System.Data.SqlClient;

namespace Frogism.Tests {
  [TestFixture]
  public class AuthorManagerTest {
    [Test]
    public void NewAuthorManger() {
      IAuthorManager am = ManagerService.GetAuthorManager();
    }
    [Test]
    public void GetAll() {
      IAuthorManager am = ManagerService.GetAuthorManager();
      IEnumerable<IAuthor> authors = am.GetAll();
      Assert.IsNotNull(authors);
    }
    [Test]
    public void GetOneById() {
      IAuthorManager am = ManagerService.GetAuthorManager();
      IAuthor author = am.Get(1);
      Assert.IsNotNull(author);
    }
    [Test]
    public void AuthorNameNotNull() {
      IAuthorManager am = ManagerService.GetAuthorManager();
      IAuthor author = am.Get(1);
      Assert.IsNotNull(author.Name);
    }
    [Test]
    public void CreateAuthor() {
      IAuthorManager am = ManagerService.GetAuthorManager();
      Author author = new Author() { Name = "Test Name" };
     // am.Insert(author);
      Assert.Less(0, am.Insert(author).Id);

    }
    [TearDown]
    public void DeleteTestAuthor() {
      using (var conn = new System.Data.SqlClient.SqlConnection(@"Data Source=.\SQL2008;Initial Catalog=Frogism;Integrated Security=True") ){
        conn.Open();
        var cmd = conn.CreateCommand();
        cmd.CommandType = System.Data.CommandType.Text;
        cmd.CommandText = "delete from author where name='Test Name'";
        cmd.ExecuteNonQuery();
      }
    }
    
  }
}
